/*
 * table_StorageManager.c
 *
 *  Created on: 2012/03/30
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
/**/
typedef struct _STORAGEMANAGER
{
	AST     astVari;
	AST     astFunc;
	AST     astLinkage;
	AST    astOpe;
} STORAGEMANAGER, *PSTORAGEMANAGER;

#define TableSize  (sizeof(STORAGEMANAGER ))
#define TableType  PSTORAGEMANAGER
#define stTable stStorageManagerManager.memoryBlocks
#define maxTable stStorageManagerManager.maxRecordNum
#define  maxNumPerBlk  (stStorageManagerManager.astMaxNum_Block)

static TABLEMANAGER stStorageManagerManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stStorageManagerManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stStorageManagerManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stStorageManagerManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stStorageManagerManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stStorageManagerManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}

//ACCESS_IDX_FIELD tablechain;
static AST getVari( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astVari;
}
/* set method */
static AST  setVari( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astVari = idx;
}
static AST getFunc( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFunc;
}
/* set method */
static AST  setFunc( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astFunc = idx;
}
static AST getLinkage( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLinkage;
}
/* set method */
static AST setLinkage( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astLinkage = idx;
}
static AST getOperand( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astOpe;
}
/* set method */
static AST setOperand( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, idx );
		return 0;
	}
	return pTbl->astOpe = idx;
}
const STORAGEMANAGER_ACCESS stStorageManagerAccess = {
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,
		{
				getVari,
				setVari
		},
		{
				getFunc,
				setFunc
		},
		{
				getLinkage,
				setLinkage
		},
		{
				getOperand,
				setOperand
		}
};
